package com.qf.cx.simplenms.readergroup.tag;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import com.qf.cx.simplenms.reader.model.AntennaModel;
import com.qf.cx.simplenms.reader.tag.Statistic;
import com.qf.cx.simplenms.reader.tag.Tag;
import com.qf.cx.simplenms.reader.tag.Tag.ReadOpResult;
import com.qf.cx.simplenms.reader.tag.Tag.VehicleInfo;
import com.qf.cx.simplenms.tagmemory.model.TagMemoryModel.Identifier;

/**
 * 表示reader group 上报的标签，tid相同表示同一个标签
 * 
 * @author wanghaoming
 *
 */
public class ReaderGroupTag {
	private AntennaModel antenna;
	private Tag tag;
	private final Map<AntennaModel, Statistic> statistics = new HashMap<>();

	public Map<AntennaModel, Statistic> getStatistics() {
		return statistics;
	}

	public void mergeStatistics(Map<AntennaModel, Statistic> statistics) {
		for (Entry<AntennaModel, Statistic> entry : statistics.entrySet()) {
			Statistic statistic = this.statistics.get(entry.getKey());
			if (statistic == null) {
				this.statistics.put(entry.getKey(), entry.getValue());
			} else {
				statistic.mergeStatistic(entry.getValue());
			}
		}
	}

	public AntennaModel getAntenna() {
		return antenna;
	}

	public void setAntenna(AntennaModel antenna) {
		this.antenna = antenna;
	}

	public Tag getTag() {
		return tag;
	}

	public void setTag(Tag tag) {
		this.tag = tag;
	}

	public Map<Identifier, VehicleInfo> getVehicleInfos() {
		if (tag == null) {
			return Collections.emptyMap();
		}
		return tag.getVehicleInfos();
	}

	public Map<Identifier, ReadOpResult> getReadOpResults() {
		if (tag == null) {
			return Collections.emptyMap();
		}
		return tag.getReadOpResults();
	}

	public String getTid() {
		if (tag == null) {
			return null;
		}
		return tag.getTid();
	}

	@Override
	public String toString() {
		return "ReaderGroupTag [antenna=" + antenna + ", tag=" + tag + ", statistics=" + statistics + "]";
	}

}
